
import axios from 'axios'
import router from "@/router"
// import { Message } from 'element-ui'
axios.interceptors.request.use(config => {
    if (localStorage.getItem('token')) {
        config.headers['Authorization'] = 'Bearer ' + localStorage.getItem('token');
    }
    return config;
},
    err => {
        return Promise.reject(err);
    });

// 定义响应拦截器
axios.interceptors.response.use(function (response) {
    if (response.data.code == '409') {
        // Message({
        //     message: "登录已过期!",
        //     type: 'error',
        //     duration: 5 * 1000
        //   })
        localStorage.removeItem('token')
        localStorage.removeItem('user')
        localStorage.removeItem('menuList')
        localStorage.removeItem('menu')

        router.replace({
            path: '/Login',
        });

    }
    return response
}, function (error) {
    if (error.response.data.code == 409) {
        localStorage.removeItem('token')
        localStorage.removeItem('user')
        localStorage.removeItem('menuList')
        localStorage.removeItem('menu')

        router.replace({
            path: '/Login',
        });
    }
    return Promise.reject(error)

})
export default axios